from flask import Blueprint, jsonify
from APP.models.cpu import Cpu
from APP.utils.Result import Result

cpu_bp = Blueprint('cpu', __name__)

@cpu_bp.route('/api/cpu', methods=['GET'])
def get_cpu_data():
    cpus = Cpu.query.all()

    result = [
        {
            'id': cpu.id,
            'metric_name': cpu.metric_name,
            'value': float(cpu.value),
            'timestamp_value': cpu.timestamp_value.isoformat()
        }
        for cpu in cpus
    ]

    return jsonify(Result.success(result).to_dict())
